<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="author" content="hexinyang">
		<title>副卡升级</title>
		<script language="javascript" src="../script/common.js" type="text/javascript"></script>
		<script language="javascript" src="../script/card.js" type="text/javascript"></script>
		<script language="javascript" src="../script/print.js" type="text/javascript"></script>
		<script language="javascript" type="text/javascript">
			function load(){
				Eui.showNavigation();
				setPages(["readcardview","detview"])	
				CardMgnt.cardUser.show("companyUserDetail",null,CardMgnt.COMPANYUSER);
			}
			function btnCanUpdate(s){
				$("readDriverCardBtn").disabled = s;
				$("updateMainCardBtn").disabled = !s;
			}
			//重置
			function onCancel(){
				switchPage("readcardview");
				btnCanUpdate(false);
				var forms = document.getElementsByTagName("FORM");
				for (var i=0;i<forms.length;i++){
					forms[i].reset();
				}
			}
			
			//读副卡
			function readDriverCard(){
				try{
					var data = CardMgnt.onFindCard("readCardForm","mgntQueryService.checkFitUpdate")
					data.customer = data.companyCustomer
					CardMgnt.cardUser.showData("companyUserDetail",data,CardMgnt.COMPANYUSER);
					btnCanUpdate(true);
				}catch(e){
					showError(e.description);
					btnCanUpdate(false);
					return;
				}
			}
			//升副卡
			function updateMainCard(){
				try{
					if(checkTypeForm.checkType[0].checked){
						if (!showQuestion("请插入主卡后点击确定升级副卡（原有主卡将变为普通司机卡），或取消返回。")) return;
						try{
							var msg = "当前主卡和副卡不匹配！！"
							CardMgnt.checkMasterCard(readCardForm.companyUserId.value,msg);
						}catch(e){showError(e.description);return;}
					}
					else{
						if (!showQuestion("请点击确定升级副卡（原有主卡将变为普通司机卡），或取消返回。")) return;
					}
					var asn = readCardForm.asn.value;
					var cardData = DWR.syncCall("cardMgntService.upgradeChildCard",asn);
					showInformation("副卡：<br>["+asn+"]升级主卡成功！"+(cardData.oldMasterAsn?"<br>原主卡：<br>["+cardData.oldMasterAsn + "]降级为普通司机卡！":""));
					switchPage("detview");
					CardMgnt.showPrintView("detview","fit_update_bill",cardData.logId,"副卡升级凭证");
					try{WebPrint.print('billview');}catch(e){showWarning("打印出错："+e.description);return;}					
				}
				catch(e){
					showError(e.description);
					btnCanUpdate(false);
					return;
				}
			}
		</script>
	</head>
<body onload="load()">
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="readcardview">
		<div id="companyUserDetail" class="form">
		</div>
		<div class="form">
			<div class="formTitle">副卡卡片信息</div>
			<form name="readCardForm" id="readCardForm">
				<input type="hidden" name="companyUserId">
				<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="label6">
					<tr>
						<td><label>卡&nbsp;&nbsp;&nbsp;&nbsp;号</label> <input type="text" name="asn" readonly class="readonly"></td>
						<td><label>有 效 期</label> <input type="text" name="expiredTime" readonly class="readonly"></td>
					</tr>
					<tr>
						<td><label>卡 类 型</label> <input type="text" name="subCardTypeText" readonly class="readonly"></td>
						<td><label>卡片状态</label> <input type="text" name="statusText" readonly class="readonly"></td>
					</tr>
				</table>
			</form>
			<form name="checkTypeForm" id="checkTypeForm">
				<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="label6">
					<tr>
						<td colspan=2><label>单位帐户校验</label> <input type="radio" name="checkType" value="1" checked>
							使用主卡 <input type="radio" name="checkType" value="2">使用证件<span class=red>（请在读卡后对照客户帐户信息）</span></td>
					</tr>
				</table>
			</form>
		</div>
		<p>
			<button id="readDriverCardBtn" onclick="readDriverCard()">读副卡</button>
			<button id="updateMainCardBtn" onclick="updateMainCard()" disabled>升级副卡</button>
			<button onclick="onCancel()">重 置</button>
		</p>
	</div>
	<!--凭证页面-->
	<div id="detview" style="display:none;">
	</div>
</body>
</html>